<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.0/axios.js"></script>
</head>
<body>
    <button id="getUserInfo" type="button">获取用户信息</button>
    <button id="addUser" type="button">添加用户</button>
    <button id="deleteUser" type="button">删除</button>
    <script type="text/javascript">
        window.onload = function () {
            let getUserInfo = document.getElementById("getUserInfo");
            getUserInfo.onclick = function () {
                axios({
                    url: 'http://127.0.0.1:2022/user/info',
                    method: 'get',
                    params: {
                        id: 1
                    }
                }).then(res => {
                    const { code, data, msg } = res.data
                    console.log(res.data)
                }).catch(err => {
                    console.log(err)
                })
            }

            let addUser = document.getElementById("addUser");

            addUser.onclick = function () {
                const data = {
                    userId: 2022,
                    username: '全栈小白'
                }
                axios({
                    url: 'http://127.0.0.1:2022/user/save',
                    method: 'post',
                    data
                }).then(res => {
                    console.log(res.data)
                }).catch(err => {
                    console.log(err)
                })
            }

            let deleteUser = document.getElementById("deleteUser");
            deleteUser.onclick = function () {
                axios({
                    url: 'http://127.0.0.1:2022/user/remove/2022',
                    method: 'delete',
                }).then(res => {
                    console.log(res.data)
                }).catch(err => {
                    console.log(err)
                })
            }
        }
    </script>
</body>
</html>